<?php 
include_once('connection/connection.php');
//session_start();
//ob_start();
include('header.php');
include('menu.php');
include('config.php');
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<title>Hand Pump Scheme</title>
<script language="Javascript" type="text/javascript" src="js/ajaxFunction_q2.js"></script>
<script language="Javascript" type="text/javascript" src="js/ajaxFunction1_q2.js"></script>
<script language="Javascript" type="text/javascript" src="js/validate2.js"></script>
<script language=javascript>
function mult()
{
	var value1=document.getElementById('DP_population').value;
	var value2=(value1 * 0.04);
	document.getElementById('DP_water_demand').value=value2;	
}
function mult2()
{
	var value1=document.getElementById('factor1').value;
	var value2=document.getElementById('population_benefited1').value;
	var value3=Math.round(value1 * value2);
	document.getElementById('present_population1').value=value3;
	//alert(value3);	
	alert('Value of Population Benefited Field is '+ value2 +', Present Population is '+ value3 +' and Population Factor is ' + value1);
}
</script>
</head>
<body onLoad="enable_text50(false)">
<?php
date_default_timezone_set('Asia/Kolkata');
$stamp = time();
$getdate = getdate($stamp);
	////////////////////////////////////////// function for dob starts //////////////
function dpulldown($name,$d,$m,$y)//This function will provide the pulldown for date
{
	$stamp = time();
	$getdate = getdate($stamp);
	$months = array(1 => 'January','February','March','April','May','June','July','August','September','October','November','December');
	echo'<select name="'.$name.'date" class="date">';
	for($date = 1; $date <= 31; $date++)
	{
		echo'<option value="'.$date.'" ';if($d == $date) echo'selected="selected"'; echo'>'.$date.'</option>';
	}
	echo'</select>';
	echo'<select name="'.$name.'month" class="date">';
	foreach($months as $key => $value)
	{
		echo'<option value="'.$key.'" ';if($m == $key) echo'selected="selected"'; echo'>'.$value.'</option>';
	}
	echo'</select>';
	echo'<select name="'.$name.'year" class="date">';
	for($year = 2005; $year <= ($getdate['year']); $year++)
	{
		echo'<option value="'.$year.'" ';if($y == $year) echo'selected="selected"'; echo'>'.$year.'</option>';
	}
	echo'</select>';
}
if(isset($_POST['submit']))
{
		$fclick = true;
		$dob = $_POST['dobyear'].'-'.$_POST['dobmonth'].'-'.$_POST['dobdate'];
		$id=$_POST['id'];
		$_SESSION['q2_id']=$id;
		$form_id=$_POST['form_id'];
		$_SESSION['form_id']=$form_id;
		$district=$_POST['district'];
		$block=$_POST['block'];
		$tehsil=$_POST['tehsil'];
		$panchayat=$_POST['panchayat'];
		$village=$_POST['village'];
		$cvc=$_POST['cvc'];
		$scheme_name=$_POST['scheme_name'];
		$year_comm=$_POST['year_comm'];
		$capital_cost=$_POST['capital_cost'];
		if($_POST['scheme_sactioned']!='Other')
		{
			$scheme_sactioned=$_POST['scheme_sactioned'];
		}
		else
		{
			$scheme_sactioned=$_POST['scheme_sactioned_other'];
		}
		$population_benefited=$_POST['population_benefited1'];
		/*$qr="SELECT * FROM tbl_lookup_pop_factor WHERE district_id = '$district'";
		$res=mysql_query($q);
		$row=mysql_fetch_array($res);
		$factor=$row['population_factor'];
		echo $factor;*/
		$present_population=$_POST['present_population1'];
		//$present_population=round($present_population*$factor);
		$DP_population=$_POST['DP_population'];
		$service_level=$_POST['service_level'];
		$DP_water_demand=($_POST['DP_population'] * $_POST['service_level']) / 1000;
		$habit_count=$_POST['habit_count'];
		//echo "Habitation Count :".$habit_count;
		$q1="INSERT INTO tbl_dtls_q2_main(id, form_id, district_id, block_id, tehsil_id, panchayat_id, village_id, census_vil_code, date,type_scheme,scheme_name, year_comm, capital_cost, scheme_sanction, population_benefited, present_population, DP_population, DP_water_demand, post_date) VALUES('$id', '$form_id', '$district','$block', '$tehsil', '$panchayat','$village', '$cvc','$dob','HP', '$scheme_name', '$year_comm', '$capital_cost', '$scheme_sactioned', '$population_benefited', '$present_population', '$DP_population', '$DP_water_demand', NOW())";
			//echo $q1;
			$r1=mysql_query($q1);
			if($r1)
			{
				//header('Location: questionnaire2_2.php');
				//echo "success 1<br>";	
				$relocatePage=true;		
			}
			else 
			{
				$errorIns="Error inserting main table <br>";
			}
			//$q3="SELECT MAX(id) AS q2_id FROM tbl_dtls_q2_main";
			$q3="SELECT id FROM tbl_dtls_q2_main where form_id='$form_id'";
			$r3=mysql_query($q3);
			$x=mysql_fetch_array($r3);
			$q2_id=$x['id'];
			$_SESSION['q2_id']=$q2_id;
			//echo $q2_id;exit;
			$_SESSION['habit_count']=$habit_count;
			//echo $habit_count;
			for($i=1; $i<=$habit_count; $i++)
			{
				$habit_code = 'habit_code'.$i;
				$habit_name = 'habit_name'.$i;
				$hp_no = 'hp_no'.$i;
				//echo "<br>";
				$sp_no = 'sp_no'.$i;
				$type_mh_oh='type_mh_oh'.$i;
				$habit_code=$_POST[$habit_code];	
				$habit_name=$_POST[$habit_name];
				$type_mh_oh=$_POST[$type_mh_oh];
				$hp_no=$_POST[$hp_no];
				//echo "<br>";
				$sp_no=$_POST[$sp_no];
				$sum[$i] = $hp_no;
				$arr_hab_count[$habit_name] = $hp_no ;
				$arr_hab_count_habit[$habit_code] = $hp_no ;
				//echo "hp==". $hp_no;
				$arr_habit_name[$i]["name"]=$habit_name;
				$arr_habit_code[$i]["code"]=$habit_code;
				$_SESSION['arr_habit_name']=$arr_habit_name;
				$_SESSION['arr_habit_code']=$arr_habit_code;
				/*-------------------------------------------*/
				$q4="INSERT INTO tbl_dtls_q2_habit(q2_id, habit_code, habit_name, type_mh_oh, hp_no, sp_no) VALUES ('$q2_id', '$habit_code', '$habit_name', '$type_mh_oh', '$hp_no', '$sp_no')";
			//echo $q4;
				$r4=mysql_query($q4);
			}	
			$sum = array_sum($sum);
			//print_r ($arr_hab_count); echo "<br>";
			$_SESSION['sum']=$sum;
			$_SESSION['arrSource'] = $arr_hab_count;
			$_SESSION['arrSourceHabit']=$arr_hab_count_habit;
			
			//print_r($arr_hab_count);
			//print_r($arr_hab_count_habit);exit;
			if($r4)
			{
				//header('Location: questionnaire2_2.php');
				//echo "success 2";
				$relocatePage=true;	
			}
			else 
			{
				$errorIns .= "Error inserting habit table <br>";
			}
			$num_habit=$_POST['num_habit'];
			for($i=1; $i<=$num_habit; $i++)
			{
				$un_habit='un_habit'.$i;
				$un_habit=$_POST[$un_habit];
				$q5="INSERT INTO tbl_dtls_q2_unhabit(q2_id, unhabit_name) VALUES ('$q2_id', '$un_habit')";
				$r5=mysql_query($q5);	
			}	
			if($r5)
			{
				$relocatePage=true;
				//echo "success 2";
				//header('Location: questionnaire2_2.php');
			}
			else 
			{
				$errorIns.="Error inserting un_habit table <br>";
			}
			
			if($errorIns==0) 
			{
				header('Location: questionnaire2_2.php');
			}
			else 
			{
				echo $errorIns;exit;
			}
}
else
{
	$fclick = false;
	$flag=0;
   	$_POST['present_population'] = '';
}
?>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" name="questionnaire2" id="questionnaire2" onSubmit="mult2()">
	<table border="0" width="800" id="table1" cellspacing="0" cellpadding="0" style="padding-left:5px; padding-top:10px">
		<tr>
			<td height="26" colspan="2" bgcolor="#EEEEEE" align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">
		  Hand Pump Scheme</font></td>
		</tr>
		
		<tr>
			<td height="17" colspan="2" bgcolor="#EEEEEE" align="center">
				
		  <font style="font-size: 8.5pt" face="Arial" color="#000000">Page 1</font></p>			</td>
		</tr>
		<tr>
			<td height="15" colspan="2" align="center" bgcolor="#EEEEEE"><font face="Arial" style="font-size: 8.5pt" color="#000000">(This Web Application is More Compatible with Mozilla Firefox and Google Chrome)</font></td>
		</tr>
		
		<tr>
			<td height="28" colspan="2" bgcolor="#C5D8EB"><font color="#000000">&nbsp;</font>
		      <span style="color:#006699"><font style="font-size: 8.5pt; font-weight: 700" face="Arial">
			1. Scheme Details </font></span></td>
		</tr>
		<tr>
			<td colspan="2"><table border="0" width="800" id="table6" bgcolor="#EEEEEE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="4">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="289" height="27">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Type of the Scheme </font></td>
					<td width="158"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><b>HP</b></font></td>
				    <td width="81"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Date</font></td>
				    <td width="265"><?php dpulldown('dob',$getdate['mday'],$getdate['mon'],$getdate['year']);?></td>
				</tr>
				<tr>
					<td width="289" height="30">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Name of the Schemes </font></td>
					<td colspan="3">
									<input name="scheme_name" type="text" id="scheme_name" class="txt" size="51"></td>
				</tr>
				<tr>
					<td width="289" height="32">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Year of Commissioning</font></td>
					<td colspan="3">
	                    <select size="1" name="year_comm" id="year_comm" class="txt">
						<option selected value="0">Not Provided</option>
						<?php 
						foreach($year_comm as $key=>$val)
						{
		   					echo "<option value=$val>$val</option>";
						}
						?>
						</select></td>
				</tr>
				<tr>
					<td width="289" height="32">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Capital Cost (in <img src="images/26rup1.jpg" width="10"> Lakh)</font></td>
					<td colspan="3">
	<input name="capital_cost" type="text" id="capital_cost" class="txt" size="20" onBlur="float(this)"></td>
				</tr>
				<tr>
					<td width="289" height="31">&nbsp;
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">
					Schemes Sanctioned Under </font></td>
					<td colspan="3">
						<select size="1" name="scheme_sactioned" id="scheme_sactioned" class="txt" onChange="enable_sanc12(true)">
						<option selected value="0">Select Scheme</option>
						<?php 
						foreach($scheme as $key=>$val)
						{
		   					echo "<option value=$val>$val</option>";
						}
						?>
					  </select>				  </td>
			  </tr>
				<tr>
				  <td width="289" height="26">&nbsp;</td>
					<td colspan="3">
						 <font style="font-size: 8pt" face="Verdana" color="#000000">&nbsp;If Other then specify&nbsp;</font><input type="text" name="scheme_sactioned_other" id="scheme_sactioned_other" class="txt">					</td>
				</tr>
				<tr>
				  <td height="26">&nbsp;</td>
				  <td colspan="3">&nbsp;</td>
			  </tr>
				</table>
		  </td>
		</tr>
		<tr>
			<td height="28" colspan="2" bgcolor="#C5D8EB"><font color="#000000">&nbsp;</font>
		      <span style="color:#006699"><font style="font-size: 8.5pt; font-weight: 700" face="Arial">
			2. Location Details </font></span></td>
		</tr>
		
		<tr>
			<td colspan="2" bgcolor="#EEEEEE">
			<span style="font-size: 3pt">&nbsp;</span></td>
		</tr>
		<tr>
			<td colspan="2">
			<table border="0" width="797" id="table2" bgcolor="#EEEEEE" cellspacing="1" cellpadding="0">
				<tr>
					<td width="158">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					District</font></td>
					<td width="253">
									<font id="district">
						<select name="district" id="district" class="txt">
						<option value="0">Select District</option>
       				  </select></font><span id="districtLoader"></span>
					
					<font id="factor">
				  <input type="hidden" size="20" class="txt5"></font>					</td>
					<td colspan="2">
					  <p align="right"></td>
				</tr>
				<tr>
					<td width="158">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Block</font></td>
					<td width="253">
					<font id="block">
						<select name="block" class="txt">
						<option value="0">=============</option>
				  </select></font><span id="blockLoader"></span></td>
					<td width="133">
					<p align="left">
				  <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Revenue Tehsil&nbsp; </font></td>
					<td width="248">
	<font id="tehsil">
					<select name="tehsil" class="txt">
						<option value="0">=============</option>
				</select></font><span id="tehsilLoader"></span></td>
				</tr>
				
		
				<tr>
					<td width="158">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Grampanchayat&nbsp;					</font></td>
					<td width="253">
									<font id="panchayat">
						<select name="panchayat" class="txt">
						<option value="0">=============</option>
				  </select></font><span id="panchayatLoader"></span>																	                    </td>
					<td width="133">&nbsp;
						<font style="font-size: 8.5pt" face="Verdana" color="#000000">Census Village Code</font></td>
					<td width="248"><font id=cvc>
						<input type="text" size="20" class="txt" value="">	
				  </font>				  </td>
				</tr>
				<tr>
					<td width="158">&nbsp;
					<font style="font-size: 8.5pt" face="Verdana" color="#000000">
					Village Covered &nbsp;&nbsp;Name(MH)</font></td>
					<td width="253">
					<font id="village">
						<select name="village" class="txt">
						<option value="0">=============</option>
				  </select></font><span id="villageLoader"></span>									</td>
					<td width="133"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Form ID </font></td>
					<td width="248">
									<div id="form_id">
					<input type="text" size="20" class="txt">	
				</div></td>
				</tr>
				<tr>
					<td width="158">&nbsp;</td>
					<td width="253">&nbsp;</td>
					<td width="133">&nbsp;</td>
					<td width="248">&nbsp;</td>
				</tr>
				<tr>
			<td height="28" colspan="2" bgcolor="#C5D8EB"><font color="#000000">&nbsp;</font>
		      <span style="color:#006699"><font style="font-size: 8.5pt; font-weight: 700" face="Arial">
			Other Habitation covered </font></span></td>
		</tr>
				
			  </table>			</td>
		</tr>
		<tr>
			<td colspan="2">
			<table border="0" width="800" id="table4" cellspacing="1" cellpadding="0" bgcolor="#EEEEEE">
				
				<tr>
					<td width="19%" align="center" bgcolor="#CCCCCC">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Code No. </font>
					</address>
					<address>
					<font face="Verdana" color="#990000" style="font-size: 8pt; font-style: normal">
				  (Census Village/ IMIS)</font></address></td>
					<td align="center" width="23%" bgcolor="#CCCCCC">
					<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
					Habitation Name</font></td>
					<td align="center" width="18%" bgcolor="#CCCCCC"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Type MH/OH</font></td>
					<td align="center" width="20%" bgcolor="#CCCCCC">
					<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
					No. of HP's</font></td>
					<td align="center" width="20%" bgcolor="#CCCCCC">
					<address>
						<span style="font-style: normal">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
				  No. of Single Phase</font></span></address></td>
				</tr>
			  </table></td></tr>
			  <tr><td colspan="6"><div id="habit"></div></td></tr>
			  <tr><td colspan="5">&nbsp;</td></tr>
			<tr>
			<td width="166" height="22" bgcolor="#EEEEEE"><font color="#000000">&nbsp;
			<font style="font-size: 8.5pt; font-weight: 700" face="Arial">No. of Unlisted Habitation</font></font></td>
			<td width="584" bgcolor="#EEEEEE"><input type="text" name="num_habit" id="num_habit" value="" class="txt5" onKeyUp="showhabit();numeric(this)"></td>
		</tr>
		<tr><td colspan="4">&nbsp;</td></tr>
		<tr>
			<td colspan="4"><div id="show_unhabit"></div></td>
		</tr>
		<tr><td colspan="4">&nbsp;</td></tr>
		<tr>
			<td height="28" colspan="2" bgcolor="#C5D8EB"><font color="#000000">&nbsp;</font>
		      <span style="color:#006699"><font style="font-size: 8.5pt; font-weight: 700" face="Arial">
			4. Population </font></span></td>
		</tr>
				
		<tr>
			<td colspan="2">
			<table border="0" width="800" id="table8" bgcolor="#EEEEEE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="5">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="165">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Population Benefited </font></td>
				  <td width="108">
				  <div id="population_benefited">
				    <input type="text" class="txt5" onBlur="numeric(this)" size="20">
				  </div>
				  <!--<input name="population_benefited" type="text" class="txt5" id="population_benefited" size="20" onBlur="mult2();numeric(this)">-->				  </td>
					<td width="148">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">
				  &nbsp;Present Population&nbsp;&nbsp;&nbsp; </font></td>
				  <td width="372">
				 <div id="present_population">
					<input type="text" size="20" class="txt5">
					</div>
				  <!--<input name="present_population" type="text" class="txt5" id="present_population" size="20" readonly onBlur="numeric(this)">
			&nbsp;<font style="font-size: 8.5pt" face="Verdana" color="#000000">1.29 times of Population Benefited</font>-->				  </td>
				</tr>
				<tr>
					<td width="165">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					(as per 2001 census)</font></td>
					<td width="108">&nbsp;</td>
					<td width="148">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					(2010)</font></td>
					<td width="372">&nbsp;</td>
				</tr>
			  </table></td>
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td height="28" colspan="2" bgcolor="#C5D8EB"><font color="#000000">&nbsp;</font>
		      <span style="color:#006699"><font style="font-size: 8.5pt; font-weight: 700" face="Arial">
			Engineering Aspects </font></span></td>
		</tr>
		
		<tr>
			<td colspan="2">
			<table border="0" width="800" id="table9" bgcolor="#EEEEEE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="5">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="263">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Design Parameters</font></td>
					<td colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td width="263">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp; 
					Population ( As per Design )</font></td>
					<td colspan="2">
				<input name="DP_population" type="text" id="DP_population" class="txt5" size="20" onBlur="numeric(this)"></td>
				    <td width="127"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Select Service Level</font></td>
				    <td width="299">
				      <select name="service_level" id="service_level">
					  <option value="40">40</option>
					  <option value="70">70</option>
		          </select>				    </td>
				</tr>
				<tr>
					<!--<td width="302">&nbsp;<font style="font-size: 8.5pt" face="Verdana" color="#000000">Water Demand (As per Design )in KLD</font></td>-->
					<td colspan="5">
						<input name="DP_water_demand" type="hidden" id="DP_water_demand"  class="txt5" size="20">&nbsp;
						<!--<font style="font-size: 8.5pt" face="Verdana" color="#000000">0.04 times of population</font>-->						</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td colspan="5"><p align="center">
			  <input name="submit" type="submit" id="submit"  value="Click for continue" onClick="return validate1()">
		  &nbsp;	</td></tr>
			  </table></td>
		</tr>
		</table>
  </form>
</div>


</body>

</html>